package cn.mw.cmdb.enums;

import java.time.LocalDate;
import java.time.Period;
import java.time.ZoneId;
import java.util.Date;

public enum VideoUsedYearsEnum {
    ThreeYearsBelow("3年以下"),
    ThreeToFiveYears( "3-5年"),
    FiveToSevenYears("5-7年"),
    SevenToTenYears("7-10年"),
    TenYearsOver("10年以上"),
    Unknown("未知");
    private final String desc;

    VideoUsedYearsEnum(String desc) {
        this.desc = desc;
    }

    public static String getVideoUsedYearsByDate(Date date) {
        if (date==null){
            return Unknown.desc;
        }
        LocalDate currentDate=LocalDate.now();

        LocalDate paramDate=date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();

        Period period= Period.between(paramDate,currentDate);

        int yearsDifference=period.getYears();

        if(period.getMonths()>0||period.getDays()>0){
            yearsDifference+=1;
        }
        switch (yearsDifference){
            case 0:
            case 1:
            case 2:
            case 3:
                return ThreeYearsBelow.desc;
            case 4:
            case 5:
                return ThreeToFiveYears.desc;
            case 6:
            case 7:
                return FiveToSevenYears.desc;
            case 8:
            case 9:
            case 10:
                return SevenToTenYears.desc;
            default:
                return TenYearsOver.desc;
        }
    }
}
